package com.ruoyi.customer.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.utils.StringUtils;
import java.util.List;
import java.util.Map;
import com.ruoyi.customer.mapper.BdCustomerMapper;
import com.ruoyi.customer.domain.BdCustomer;
import com.ruoyi.customer.service.IBdCustomerService;

/**
 * 客户Service业务层处理
 *
 * @author ruoyi
 * @date 2023-11-14
 */
@Service
public class BdCustomerServiceImpl extends ServiceImpl<BdCustomerMapper, BdCustomer> implements IBdCustomerService {

    @Autowired
    private BdCustomerMapper bdCustomerMapper;

    /**
     * 查询客户列表
     *
     * @param bdCustomer 客户
     * @return 客户
     */
    @Override
    public List<BdCustomer> selectBdCustomerList(BdCustomer bdCustomer)
    {
        List<BdCustomer> bdCustomerList = bdCustomerMapper.selectList(buildQueryWrapper(bdCustomer));
        return bdCustomerList;
    }


    private LambdaQueryWrapper<BdCustomer> buildQueryWrapper(BdCustomer query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<BdCustomer> lqw = Wrappers.lambdaQuery();
        lqw.eq(StringUtils.isNotBlank(query.getNumber()), BdCustomer::getNumber, query.getNumber());
        lqw.like(StringUtils.isNotBlank(query.getName()), BdCustomer::getName, query.getName());
        lqw.eq(StringUtils.isNotBlank(query.getNameAbb()), BdCustomer::getNameAbb, query.getNameAbb());
        lqw.eq(StringUtils.isNotBlank(query.getNameEn()), BdCustomer::getNameEn, query.getNameEn());
        lqw.eq(StringUtils.isNotBlank(query.getCusDescribe()), BdCustomer::getCusDescribe, query.getCusDescribe());
        lqw.eq(StringUtils.isNotBlank(query.getType()), BdCustomer::getType, query.getType());
        lqw.eq(StringUtils.isNotBlank(query.getLogo()), BdCustomer::getLogo, query.getLogo());
        lqw.eq(StringUtils.isNotBlank(query.getAddress()), BdCustomer::getAddress, query.getAddress());
        lqw.eq(StringUtils.isNotBlank(query.getWebsite()), BdCustomer::getWebsite, query.getWebsite());
        lqw.eq(StringUtils.isNotBlank(query.getEmail()), BdCustomer::getEmail, query.getEmail());
        lqw.eq(StringUtils.isNotBlank(query.getPhone()), BdCustomer::getPhone, query.getPhone());
        lqw.eq(StringUtils.isNotBlank(query.getContacts()), BdCustomer::getContacts, query.getContacts());
        lqw.eq(StringUtils.isNotBlank(query.getContactsPhone()), BdCustomer::getContactsPhone, query.getContactsPhone());
        lqw.eq(StringUtils.isNotBlank(query.getContactsEmail()), BdCustomer::getContactsEmail, query.getContactsEmail());
        lqw.eq(StringUtils.isNotBlank(query.getContactsb()), BdCustomer::getContactsb, query.getContactsb());
        lqw.eq(StringUtils.isNotBlank(query.getContactsbPhone()), BdCustomer::getContactsbPhone, query.getContactsbPhone());
        lqw.eq(StringUtils.isNotBlank(query.getContactsbEmail()), BdCustomer::getContactsbEmail, query.getContactsbEmail());
        lqw.eq(StringUtils.isNotBlank(query.getCreditCode()), BdCustomer::getCreditCode, query.getCreditCode());
        lqw.eq(StringUtils.isNotBlank(query.getStatus()), BdCustomer::getStatus, query.getStatus());
        lqw.orderByDesc(BdCustomer::getCreateTime);
        return lqw;
    }

}
